import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import { renderWithQiankun, qiankunWindow } from "vite-plugin-qiankun/dist/helper";

let root;
function render(props) {
  const { container } = props;
  root = createApp(App);
  const c = container ? container.querySelector("#app") : document.getElementById("app");
  root.provide("global", {
    mainRouter: props.router,
    setGlobalState: props.setGlobalState,
  })
  root.mount(c);
}


renderWithQiankun({
  mount(props) {
    console.log("vue3sub mount");
    console.log(props);
    render(props);
  },
  bootstrap() {
    console.log("bootstrap");
  },
  unmount(props) {
    console.log("vue3sub unmount");
    root.unmount();
  },
  update(props) {
    console.log("vue3sub update");
    console.log(props);
  },
});

if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render({});
}
